{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "956e75e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ['create_image']='True'\n",
    "os.environ['repository']='docker.io/romeokienzler'\n",
    "os.environ['version']='0.1'\n",
    "os.environ['name']='claimed-sim-wrf'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cc70e77c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sending build context to Docker daemon   25.6kB\n",
      "Step 1/8 : FROM romeokienzler/mywrfcontainerimage\n",
      " ---> 7cf57e8f908b\n",
      "Step 2/8 : WORKDIR /wrf/WRF\n",
      " ---> Using cache\n",
      " ---> 96d7a5ddcc69\n",
      "Step 3/8 : RUN ./clean -a\n",
      " ---> Using cache\n",
      " ---> bb1a1805bf3a\n",
      "Step 4/8 : RUN ./configure\n",
      " ---> Running in dcd9136a53bd\n",
      "checking for perl5... no\n",
      "checking for perl... found /usr/bin/perl (perl)\n",
      " \n",
      "*****************************************************************************\n",
      "No environment variable NETCDF set.\n",
      "Stopping\n",
      "*****************************************************************************\n",
      " \n",
      "The command '/bin/sh -c ./configure' returned a non-zero code: 5\n"
     ]
    }
   ],
   "source": [
    "if bool(os.environ.get('create_image',False)):\n",
    "    docker_file=\"\"\"\n",
    "    FROM romeokienzler/mywrfcontainerimage\n",
    "    SHELL [\"/bin/tcsh\", \"-c\"]\n",
    "    WORKDIR /wrf/WRF\n",
    "    RUN ./clean -a\n",
    "    RUN ./configure\n",
    "    RUN ./compile em_real >&! foo\n",
    "    WORKDIR /wrf/WPS\n",
    "    RUN ./configure\n",
    "    RUN ./compile >&! foo\n",
    "    \"\"\"\n",
    "    with open(\"Dockerfile\", \"w\") as text_file:\n",
    "        text_file.write(docker_file)\n",
    "\n",
    "    !docker build -t `echo $name`:`echo $version` .\n",
    "    #!docker tag `echo $name`:`echo $version` `echo $repository`/`echo $name`:`echo $version`\n",
    "    #!docker push `echo $repository`/`echo $name`:`echo $version`\n",
    "    !rm Dockerfile\n",
    "else: \n",
    "    None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "57ab222c-9f77-495a-8f5a-080138c58f34",
   "metadata": {},
   "outputs": [],
   "source": [
    "#! /bin/sh\n",
    "ls\n",
    "docker   run   -it   --name   teachme   7cf57e8f908b   /bin/tcsh\n",
    "ls -ls\n",
    "cd WRF\n",
    "./clean -a\n",
    "./configure\n",
    "./compile em_real >&! foo\n",
    "ls -ls main/*.exe\n",
    "cd ../WPS\n",
    "./configure\n",
    "./compile >&! foo\n",
    "ls -ls *.exe\n",
    "cp namelist.wps namelist.wps.original\n",
    "cp /wrf/wrfinput/namelist.wps.docker namelist.wps\n",
    "./geogrid.exe\n",
    "ls -ls geo_em.d01.nc\n",
    "./link_grib.csh /wrf/wrfinput/fnl\n",
    "cp ungrib/Variable_Tables/Vtable.GFS Vtable\n",
    "./ungrib.exe\n",
    "ls -ls FILE*\n",
    "./metgrid.exe\n",
    "ls -ls met_em.*\n",
    "cd ../WRF/test/em_real\n",
    "ln -sf ../../../WPS/met_em* .\n",
    "cp namelist.input namelist.input.original\n",
    "cp /wrf/wrfinput/namelist.input.docker namelist.input\n",
    "mpirun -np 2 ./real.exe\n",
    "tail rsl.out.0000\n",
    "ls -ls wrfinput_d01 wrfbdy_d01\n",
    "mpirun -np 3 ./wrf.exe &\n",
    "tail rsl.out.0000\n",
    "ls -ls wrfo*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7e82c13",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
